class CreateUsers < ActiveRecord::Migration
  def self.up
    create_table :users do |t|
      t.column :lock_version,        :integer,   :null  => false
      t.column :username,            :string,    :null  => false, :limit   => 20
      t.column :password,            :string,    :null  => false, :limit   => 40
      t.column :salt,                :string,    :null  => false, :limit   => 40
      t.column :email,               :string,    :null  => false, :limit   => 50
      t.column :logo,                :binary,    :null  => false
      t.column :sent,                :boolean,   :null  => false, :default => false
      t.column :active,              :boolean,   :null  => false, :default => false
      t.column :locked,              :boolean,   :null  => false, :default => false
      t.column :expired,             :boolean,   :null  => false, :default => false
      t.column :failure,             :integer,   :null  => false, :default => 0
      t.column :remember_me_token,   :string,    :limit => 40
      t.column :remember_me_expires, :timestamp
      t.column :entries_count,       :integer,   :null  => false, :default => 0
      t.column :created_at,          :timestamp, :null  => false
      t.column :updated_at,          :timestamp, :null  => false
    end

    add_index :users, :username, :unique => true
    add_index :users, :email,    :unique => true

    create_table :roles_users, :id => false do |t|
      t.column :role_id, :integer, :null => false
      t.column :user_id, :integer, :null => false
    end

    add_index :roles_users, [ :role_id, :user_id ], :unique => true
  end

  def self.down
    drop_table :roles_users
    drop_table :users
  end
end
